package leetcode.weekly.week334;

import leetcode.helper.H;

//Solution1Test
public class Solution1 {
	public int[] leftRigthDifference(int[] nums) {
		int len = nums.length;
		int[] l = new int[len];
		int[] r = new int[len];
		for (int i = 1; i < len; i++) {
			l[i] = (i - 1 >= 0 ? l[i - 1] : 0) + nums[i - 1];
		}
		for (int i = len - 2; i >= 0; i--) {
			r[i] = (i + 1 < len ? r[i + 1] : 0) + nums[i + 1];
		}
		int[] ans = new int[len];
		for (int i = 0; i < len; i++) {
			ans[i] = Math.abs(l[i] - r[i]);
		}
		return ans;
	}

}
